<template>
	<view style="padding: 20rpx;">
		<view :style="{height: statusBarHeight+'px'}"></view>
		<view class="u-flex" style="justify-content: space-between;">
			<view class="u-flex">
				<view v-for="(item,index) in topList" :key="index"
				style="margin: 35rpx 25rpx 25rpx 10rpx;font-size: 32rpx;font-weight: bold;
				color: #9C9B97;" @click="topClick(item.id)">
					<text :class="activetop == item.id?'activetop':''">{{item.name}}</text>
				</view>
			</view>
			<view style="position: relative;flex: 1;text-align: right;">
				<image src="../../static/sous.png" mode="aspectFill"
				style="width: 50rpx;height: 50rpx;margin-right: 30rpx;" @click="sousClick"></image>
				<image src="../../static/gengduo.png" mode="aspectFill"
				style="width: 50rpx;height: 50rpx;" @click="show=!show"></image>
				<view style="position: absolute;bottom: 0;top:0;margin-top: 80rpx;width: 200rpx;text-align: center;height: 260rpx;
				right: 0;box-shadow: 0 0 10rpx 5rpx #ECF5FF;z-index: 1;background-color: #FFFFFF;
				" v-if="show">
					<view>
						<view v-for="(item,index) in topRight":key="index" style="padding: 27rpx;"
						@click="showList = item.id">
							<view style="margin: auto;"class="u-flex">
								<image :src="item.imageUrl" mode="aspectFill"
								style="width: 35rpx;height: 35rpx;"></image>
								<view>{{item.title}}</view>
							</view>
							
						</view>
					</view>

				</view>
			</view>
		</view>
		<view class="box1">
			<view style="width: 500rpx;">
				<u-notice-bar :list="centenrList"
				:volume-icon="false"></u-notice-bar>
			</view>
			<view style="display: flex;" @click="tianxieClick">
				<image src="../../static/tianxie.png" mode="aspectFill"
				style="width: 40rpx;height: 40rpx;"></image>
				<text style="margin-left: 20rpx;">编辑</text>
			</view>
		</view>
		<view class="u-flex" >
			<u-row>
				<u-col span="3" v-for="(item,index) in centenr" :key="index"
				style="text-align: center;" @click="centenrClick(item.id)">
					<text class="textcentenr"
					:class="activecentenr == item.id?'activecentenr':''">
					{{item.name}}
					</text>
				</u-col>
			</u-row>
<!-- 			<view style="display: flex;margin-left: 20rpx;">
				<image src="../../static/shaixu.png" mode="aspectFill"
				style="width: 40rpx;height: 40rpx;"></image>
				<text>筛选</text>
			</view> -->
		</view>
		<view class="box2" style="z-index: 0;">
			<view v-for="(item,index) in bookData" :key="index" style="width: 33.3%;align-items: center;margin-bottom: 50rpx;"
			class="u-flex-col"
			@click="itemClick(item.bookdataId)"  v-if="showList == 1">
				<bookshelf-item :item="item"></bookshelf-item>
			</view>
			<view  v-for="(item,index) in bookData" :key="index"
			@click="itemClick(item.bookdataId)" v-if="showList == 2" style="margin: 10rpx;">
				<book-item-name :item="item"  :indexs="1"></book-item-name>
			</view>
			<view  v-for="(item,index) in bookData" :key="index"
			@click="itemClick(item.bookdataId)" v-if="showList == 3" style="margin: 10rpx; width:47%;margin-bottom: 50rpx;"
			class="u-flex-col">
				<book-item-shuangL :item="item"></book-item-shuangL>
			</view>
		</view>
		<view v-if="bookData.length == 0" style="text-align: center;margin-top: 100rpx;">
			<text style="color: #999999;font-size: 36rpx;">暂无数据</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				showList:0,
				show:false,
				activetop:1,
				activecentenr:1,
				topList:[
					{id:1,name:"书架"},
					// {id:2,name:"圈子"},
					// {id:3,name:"历史"}
				],
				centenr:[
					{id:1,name:"全部"},
					{id:2,name:"完结"},
					{id:3,name:"连载"},
					{id:4,name:"出版"}
				],
				centenrList:[
					"寒雨连江夜入吴",
					'平明送客楚山孤',
					"洛阳亲友如相问",
					"一片冰心在玉壶"
				],
				bookshelfData:[],
				bookData:[],
				userId:0,
				topRight:[
					{id:1,title:"宫格模式",imageUrl:"../../static/icon_shuj/jiugongge.png"},
					{id:2,title:"列表模式",imageUrl:"../../static/icon_shuj/caidan.png"},
					{id:3,title:"双列模式",imageUrl:"../../static/icon_shuj/list.png"}
				],
				statusBarHeight:0
			}
		},
		mounted() {
			let that = this
			//获取手机系统信息
			const info = uni.getSystemInfoSync()
			//设置状态栏高度
			that.statusBarHeight = info.statusBarHeight
			
		},
		methods: {
			topClick(e){
				this.activetop = e
			},
			centenrClick(e){
				this.bookData = []
				this.activecentenr = e
				if(e == 1){
					this.bookData = this.bookshelfData
				}else{
					this.bookData = this.bookshelfData.filter(item=>item.state == this.centenr[e-1].name)
					
				}
			},
			//
			async getBookshelfData(userId){
				const res=await this.$myRequst({
					url:"/bookshelf/gets/"+userId
				})
				this.bookshelfData = res.data.data
				this.bookData = this.bookshelfData
				console.log(this.bookshelfData)
			},
			getUserId(){
				this.userId = uni.getStorageSync("userId")
			},
			itemClick(e){
				console.log(e)
				uni.navigateTo({
					url:"../index/bookItem/bookItem?id="+e
				})
			},
			sousClick(){
				uni.navigateTo({
					url:"../index/search-for/search-for"
				})
			},
			listshow(){
				this.showList = uni.getStorageSync("showList") || 1
			},
			tianxieClick(){
				uni.navigateTo({
					url:"./DeleteShuj/DeleteShuj"
				})
			}
		},
		onLoad() {
			this.getUserId()
			this.listshow()
		},
		onShow() {
			this.getBookshelfData(this.userId)
			this.getUserId()
		},
		onHide(){
			console.log(this.showList)
			uni.setStorageSync("showList",this.showList)
		}
	}
</script>

<style lang="scss">
.activetop{
	color: #000000;
	font-size: 42rpx;
}
.box1{
	display: flex;
	padding: 10rpx 10rpx 50rpx 0;
	justify-content: space-between;
	align-items: center;
	
}
.textcentenr{
	padding: 15rpx 40rpx;
	background-color: #F7F7F7;
	border-radius: 0.5em;
}
.activecentenr{
	background-color: #FEEFE8;
	color: #E27037;
}
.box2{
	margin: 50rpx 0rpx;
	display: flex;
	flex-flow: row wrap; 
	// justify-content: space-between;
	
}
</style>
